/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author Administrator
 */
public class reConstructZoombie {

    public static Map<String, String> zoombie = new HashMap<String, String>();

    public static void main(String[] args) throws IOException {
        readFile();
        writeFile();
    }

    public static void writeFile() throws IOException {
        String filename = "F:\\Sina\\spider\\src\\Zoombie2.txt";
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename)));
        Set keys = zoombie.keySet();
        int count = keys.size();
        for (int i = 0; i < count; i++) {
            String key = (String) keys.toArray()[i];
            writer.write(key + " " + zoombie.get(key) + "\r\n");
        }
        writer.close();
    }

    public static void readFile() throws IOException {
        String filename = "F:\\Sina\\spider\\src\\ZoombieNew.txt";
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
        String line = reader.readLine();
        while (line != null) {
            if (!line.isEmpty()) {
                String s[] = line.split(" ");
                if (s.length == 1) {
                    zoombie.put(s[0], " ");
                } else {
                    zoombie.put(s[0], s[1]);
                }

            }
            line = reader.readLine();
        }
        reader.close();
    }
}
